<template>
	<ff-button class="ff-form-submit" form-type="submit" @click="onClick">
		<slot />
	</ff-button>
</template>

<script>
	export default {
		name: "ff-form-submit",
		components: {},
		props: {

		},
		computed: {
			form() {
				let parent = this.$parent
				while (true) {
					if (parent == undefined) {
						return null
					} else if (parent.$options.name == 'ff-form') {
						return parent
					}
					parent = parent.$parent
				}
			},
		},
		data() {
			return {

			};
		},
		mounted() {

		},
		methods: {
			onClick(e) {
				this.form.validate((valid) => {
					if (valid) {
						this.$emit("click", {});
						alert('submit!');
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
		}
	}
</script>

<style>
	ff-form-submit {
		width: 100%;
		height: 100%;
		overflow: hidden;
	}

	.ff-form-submit {
		width: inherit;
		height: inherit;
		overflow: hidden;
	}
</style>